<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="用户名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入用户名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="手机号码" prop="phonenumber">
            <el-input
              v-model="queryParams.phonenumber"
              placeholder="请输入手机号码"
              clearable

              @keyup.enter.native="handleQuery"
            />
          </el-form-item>


          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-form>



        <el-table v-loading="loading" :data="userList">
          <el-table-column label="会员编号" align="center" key="userId" prop="userId" v-if="columns[0].visible" />
          <el-table-column label="会员姓名" align="center" key="trueName" prop="trueName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="会员昵称" align="center" key="nickName" prop="nickName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column :label="`组织/机构`" align="center" key="deptName" prop="dept.deptName" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="手机号码" align="center" key="phonenumber" prop="phonenumber" v-if="columns[4].visible" width="120" />
          <el-table-column label="状态" align="center" key="status" v-if="columns[5].visible">
            <template slot-scope="scope">
              {{scope.row.status==0?'启用':''}}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >

            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="zhipai(scope.row)"
              >指派</el-button>







            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>


  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect,listJgglUser ,gtShenhe,hyShenhe,hyJiaofei} from "@/api/system/user";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "User",
  dicts: ['sys_normal_disable', 'sys_user_sex'],
  components: { Treeselect },
  props:{
    propDeptId:[Number, String]
  },
  data() {
    return {
     zhipaiArr:[],
      zhipaiarr:[],//去重后的
      jgOrZzTitle:'',//机构或组织
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",

      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: 0,
        deptId: undefined,
        auditStatus:undefined,//个体
        //userType:'01',//微信用户
        //会员
        params:{
          auditStatus:1,//个体/普通用户审核状态（0待审核 1通过 2失败）
          payStatus:1,//待缴费
          renewStatus:undefined,//待续费
        }


      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true }
      ],

    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
    propDeptId:{
      deep: true,
      immediate: true,
      handler(val){
        //this.queryParams.deptId=val//指派该组织下的会员
        this.loading = true;
        listJgglUser(this.queryParams).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          console.log(this.userList)
          this.userList.forEach(item=>{
          })
          this.loading = false;

        });
      }

    }
  },

  methods: {


    /** 查询用户列表 */
    getList() {
      this.queryParams.deptId=this.propDeptId
      this.loading = true;
      listJgglUser(this.queryParams).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          console.log(this.userList)
          this.loading = false
        }
      );
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.getList();
    },
    /** 指派**/
    zhipai(row){
    this.$emit('zhipai',{data:row.userId})
    },
  }
};
</script>
<style scoped>
.gtButton{height:45px;text-align: center;line-height: 45px;background: red}
.el-form-item{margin-bottom:0px}
</style>
